package io.renren.modules.generator.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.modules.generator.dao.CourseDao;
import io.renren.modules.generator.dao.GradeclassDao;
import io.renren.modules.generator.dao.SchoolDao;
import io.renren.modules.generator.entity.CourseEntity;
import io.renren.modules.generator.entity.GradeclassEntity;
import io.renren.modules.generator.entity.SchoolEntity;
import io.renren.modules.generator.service.CourseService;



@Service("courseService")
public class CourseServiceImpl implements CourseService {
	@Autowired
	private CourseDao courseDao;
	
	@Autowired
	private GradeclassDao gradeClassDao;
	
	@Autowired	
	private SchoolDao schoolDao;
	
	@Override
	public CourseEntity queryObject(String classno){
		return courseDao.queryObject(classno);
	}
	
	@Override
	public List<CourseEntity> queryList(Map<String, Object> map){
		return courseDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return courseDao.queryTotal(map);
	}
	
	@Override
	public void save(CourseEntity course){
		courseDao.save(course);
	}
	
	@Override
	public void update(CourseEntity course){
		courseDao.update(course);
	}
	
	@Override
	public void delete(String classno){
		courseDao.delete(classno);
	}
	
	@Override
	public void deleteBatch(String[] classnos){
		courseDao.deleteBatch(classnos);
	}

	@Override
	public Map<String,String> queryCourseDetail(String classno) {
		
		Map<String,String> map = new HashMap<String,String>();
		//查询课程信息
		CourseEntity course = courseDao.queryObject(classno);
		if (course==null) {
			return null;
		}
		map.put("courseno",course.getClassno());
		map.put("coursename",course.getName());
		String tGradeNo = course.getGrade();
		GradeclassEntity grade = gradeClassDao.queryObject(tGradeNo);
		if (grade==null) {
			return null;
		}
		map.put("gradeno",grade.getGradeclassno());
		map.put("gradename",grade.getName());
		
		String schoolno = grade.getSchoolno();
		SchoolEntity school = schoolDao.queryObject(schoolno);
		if (school==null) {
			return null;
		}
		
		map.put("schoolno",school.getSchoolno());
		map.put("schoolname",school.getSchoolname());
		
		return map;
	}
	
}
